import { NEl } from 'naive-ui'
import QueryFrom from './query-from'
import BasicTable from './basic-table'
import './style/index.less'
import { proTableProps } from './typing'
import { useRequestState } from './ composables/request-state'
import { useProTableProvider } from '@/components/tables/pro-table/context'

/**
 * 通用数据表配置
 * @author ellwood
 * @date 2024-11-06
 * @version 1.0.0
 */

const proTable = defineComponent({
  name: 'ProTable',
  props: {
    ...proTableProps,
  },
  setup(props, { slots }) {
    useProTableProvider(props)
    const { requestProps } = useRequestState(props)
    return () => {
      const basicTableSlots = {
        empty: slots.empty,
        loading: slots.loading,
      }
      return (
        <NEl tag="div" class="pro-table">
          <QueryFrom />
          <BasicTable {...props} {...requestProps} v-slots={basicTableSlots} />
        </NEl>
      )
    }
  },
})

export default proTable
